<?php
set_time_limit(0); //防止执行超时
ob_end_clean();   //清空并关闭输出缓冲区


include("base_function.php");
include("base/db.php");

function analyse(&$html,$url)
{
    //仓储所在地，用户ID，用户url，销量、标题、分类、页面详细地址、价格
    //用户ID
    //用户地址
    $reg = "|<img id=\"icImg\" class=\"img img300\" itemprop=\"image\" src=\"(.*?)\" |";
    $match_count = preg_match ($reg,$html,$out);
    if($match_count == 0){
        echo "not match: $url<br>";
        return;
    }
    echo '<a href="'.$url.'" target="_black"><img src="'.$out[1].'"></a><br>';
}

function doit()
{
    open_db();
    $good_urls = query_db("select a.url,b.title from pm_product a, pm_good_info b where a.id = b.id and a.id in (select id from pm_good_info where CAST(  `watchers` AS UNSIGNED )>4710)");
    foreach ($good_urls as $good_url){
        //echo $good_url["url"]."\r\n";
        $html = http_response($good_url["url"]);
        $html = htmlspecialchars_decode($html,ENT_QUOTES);
        //file_put_contents("test.txt",$html);
        echo $good_url["title"]."<br>";
        analyse($html,$good_url["url"]);
        //break;
    }
    close_db();
}

doit();
echo "ok";

?>
